/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author wei
 */
@Entity(name="Department")
public class DepartmentEntity extends DataObjectEntity implements Serializable {

    private String name;
    
    @OneToOne
    private SystemUserEntity manager;
    
    @OneToMany(mappedBy = "department", cascade={CascadeType.ALL})//, fetch=FetchType.EAGER)
    private Collection<SystemUserEntity> employees = new HashSet<SystemUserEntity>();
    
    @ManyToMany(mappedBy="departmentRecipients", fetch= FetchType.EAGER)
    private Collection<InternalMessageEntity> messagesReceived = new HashSet<InternalMessageEntity> ();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<SystemUserEntity> getEmployees() {
        return employees;
    }

    public void setEmployees(Collection<SystemUserEntity> employees) {
        this.employees = employees;
    }

    public SystemUserEntity getManager() {
        return manager;
    }

    public void setManager(SystemUserEntity manager) {
        this.manager = manager;
    }

    public Collection<InternalMessageEntity> getMessagesReceived() {
        return messagesReceived;
    }

    public void setMessagesReceived(Collection<InternalMessageEntity> messagesReceived) {
        this.messagesReceived = messagesReceived;
    }

    @Override
    public String toString() {
        return name ;
    }
    
    @Override
    public String childToString() {
        return "DepartmentEntity{" + "name=" + name + ", manager=" + manager + ", employees=" + employees + ", messagesReceived=" + messagesReceived + '}';
    }
}
